﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FourthWallProject.GameObjects.Solids;
using Microsoft.Xna.Framework;

namespace FourthWallProject.GameObjects.GameComponents
{
    static class GameCamera
    {
        public static int WindowWidth;
        public static int WindowHeight;
        public static bool isStatic { get; set; }
        public static bool isFollowing
        {
            get { return !isStatic; }
            set { isStatic = !value; }
        }

        public static int CameraSpeed = 20;

        private static Vector2 CameraCenter;

        public static int X { get; set; }
        public static int Y { get; set; }

        public static GameObject CameraFocus { get; set; }

        public static void Update()
        {
            CameraCenter = new Vector2(X + (WindowWidth / 2), Y + (WindowHeight / 2));;
            if (!isStatic)
            {
                if (-(int)CameraFocus.Position.X + (WindowWidth / 2) < X)
                {
                    X -= CameraSpeed;
                    if (-(int)CameraFocus.Position.X + (WindowWidth / 2) >= X)
                    {
                        GameCamera.X = -(int)CameraFocus.Position.X + (WindowWidth / 2);
                    }
                }
                else
                {
                    X += CameraSpeed;
                    if (-(int)CameraFocus.Position.X + (WindowWidth / 2) <= X)
                    {
                        GameCamera.X = -(int)CameraFocus.Position.X + (WindowWidth / 2);
                    }
                }
                if (-(int)CameraFocus.Position.Y + (WindowHeight / 2) < Y)
                {
                    Y -= CameraSpeed;
                    if (-(int)CameraFocus.Position.Y + (WindowHeight / 2) >= Y)
                    {
                        GameCamera.Y = -(int)CameraFocus.Position.Y + (WindowHeight / 2);
                    }
                }
                else
                {
                    Y += CameraSpeed;
                    if (-(int)CameraFocus.Position.Y + (WindowHeight / 2) <= Y)
                    {
                        GameCamera.Y = -(int)CameraFocus.Position.Y + (WindowHeight / 2);
                    }
                }
            }
            isStatic = false;
        }
    }
}
